import pymysql

if __name__ == "__main__":
    db = pymysql.connect(
        host="localhost",
        user="root",
        password="root",
        database="test"
    )
    cursor = db.cursor()
    # SQL 删除语句
    sql = "INSERT INTO `test`.`member` (`id`, `nickname`, `loginname`, `password`) VALUES (7, '小白', 'xiaobai', '123456');"
    try:
        # 执行SQL语句
        cursor.execute(sql)
        # 提交修改
        # db.rollback()
        db.commit()
        raise ValueError("修改失败：数据格式不正确")
    except Exception as e:
        print(str(e))
        # 发生错误时回滚
        db.rollback()
    finally:
        print("hhhhhhhhhhhhhhhhhh")
    # 关闭连接
    db.close()
